using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using iBeauty.BusinessObjects;

namespace iBeauty.DAL
{
	public class BillDetailDAO
	{
		public BillDetailDAO()
		{
			DbProviderHelper.GetConnection();
		}
		public List<BillDetail> GetBillDetails()
		{
			try
			{
				List<BillDetail> lstBillDetails = new List<BillDetail>();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECT [ID],[CreateDate],[ModifiedDate],[TimeStamp],[LineNo],[ProductCode],[ProductName],[Quantity],[Price],[Total],[OddQuantity],[Content],[UnitType],[ExpireDate],[AccountId],[Note] FROM [BillDetail]",CommandType.Text);
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					BillDetail oBillDetail = new BillDetail();
					oBillDetail.ID = Convert.ToString(oDbDataReader["ID"]);

					if(oDbDataReader["CreateDate"] != DBNull.Value)
						oBillDetail.CreateDate = Convert.ToDateTime(oDbDataReader["CreateDate"]);

					if(oDbDataReader["ModifiedDate"] != DBNull.Value)
						oBillDetail.ModifiedDate = Convert.ToDateTime(oDbDataReader["ModifiedDate"]);

					if(oDbDataReader["TimeStamp"] != DBNull.Value)
						oBillDetail.TimeStamp = Convert.ToDateTime(oDbDataReader["TimeStamp"]);

					if(oDbDataReader["LineNo"] != DBNull.Value)
						oBillDetail.LineNo = Convert.ToString(oDbDataReader["LineNo"]);

					if(oDbDataReader["ProductCode"] != DBNull.Value)
						oBillDetail.ProductCode = Convert.ToString(oDbDataReader["ProductCode"]);

					if(oDbDataReader["ProductName"] != DBNull.Value)
						oBillDetail.ProductName = Convert.ToString(oDbDataReader["ProductName"]);

					if(oDbDataReader["Quantity"] != DBNull.Value)
						oBillDetail.Quantity = Convert.ToString(oDbDataReader["Quantity"]);

					if(oDbDataReader["Price"] != DBNull.Value)
						oBillDetail.Price = Convert.ToDouble(oDbDataReader["Price"]);

					if(oDbDataReader["Total"] != DBNull.Value)
						oBillDetail.Total = Convert.ToDouble(oDbDataReader["Total"]);

					if(oDbDataReader["OddQuantity"] != DBNull.Value)
						oBillDetail.OddQuantity = Convert.ToDouble(oDbDataReader["OddQuantity"]);

					if(oDbDataReader["Content"] != DBNull.Value)
						oBillDetail.Content = Convert.ToDouble(oDbDataReader["Content"]);

					if(oDbDataReader["UnitType"] != DBNull.Value)
						oBillDetail.UnitType = Convert.ToInt32(oDbDataReader["UnitType"]);

					if(oDbDataReader["ExpireDate"] != DBNull.Value)
						oBillDetail.ExpireDate = Convert.ToDateTime(oDbDataReader["ExpireDate"]);

					if(oDbDataReader["AccountId"] != DBNull.Value)
						oBillDetail.AccountId = Convert.ToInt32(oDbDataReader["AccountId"]);

					if(oDbDataReader["Note"] != DBNull.Value)
						oBillDetail.Note = Convert.ToString(oDbDataReader["Note"]);
					lstBillDetails.Add(oBillDetail);
				}
				oDbDataReader.Close();
				return lstBillDetails;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public BillDetail GetBillDetail(string ID)
		{
			try
			{
				BillDetail oBillDetail = new BillDetail();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECT [ID],[CreateDate],[ModifiedDate],[TimeStamp],[LineNo],[ProductCode],[ProductName],[Quantity],[Price],[Total],[OddQuantity],[Content],[UnitType],[ExpireDate],[AccountId],[Note] FROM [BillDetail] WHERE [ID]=@ID",CommandType.Text);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID",DbType.String,ID));
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					oBillDetail.ID = Convert.ToString(oDbDataReader["ID"]);

					if(oDbDataReader["CreateDate"] != DBNull.Value)
						oBillDetail.CreateDate = Convert.ToDateTime(oDbDataReader["CreateDate"]);

					if(oDbDataReader["ModifiedDate"] != DBNull.Value)
						oBillDetail.ModifiedDate = Convert.ToDateTime(oDbDataReader["ModifiedDate"]);

					if(oDbDataReader["TimeStamp"] != DBNull.Value)
						oBillDetail.TimeStamp = Convert.ToDateTime(oDbDataReader["TimeStamp"]);

					if(oDbDataReader["LineNo"] != DBNull.Value)
						oBillDetail.LineNo = Convert.ToString(oDbDataReader["LineNo"]);

					if(oDbDataReader["ProductCode"] != DBNull.Value)
						oBillDetail.ProductCode = Convert.ToString(oDbDataReader["ProductCode"]);

					if(oDbDataReader["ProductName"] != DBNull.Value)
						oBillDetail.ProductName = Convert.ToString(oDbDataReader["ProductName"]);

					if(oDbDataReader["Quantity"] != DBNull.Value)
						oBillDetail.Quantity = Convert.ToString(oDbDataReader["Quantity"]);

					if(oDbDataReader["Price"] != DBNull.Value)
						oBillDetail.Price = Convert.ToDouble(oDbDataReader["Price"]);

					if(oDbDataReader["Total"] != DBNull.Value)
						oBillDetail.Total = Convert.ToDouble(oDbDataReader["Total"]);

					if(oDbDataReader["OddQuantity"] != DBNull.Value)
						oBillDetail.OddQuantity = Convert.ToDouble(oDbDataReader["OddQuantity"]);

					if(oDbDataReader["Content"] != DBNull.Value)
						oBillDetail.Content = Convert.ToDouble(oDbDataReader["Content"]);

					if(oDbDataReader["UnitType"] != DBNull.Value)
						oBillDetail.UnitType = Convert.ToInt32(oDbDataReader["UnitType"]);

					if(oDbDataReader["ExpireDate"] != DBNull.Value)
						oBillDetail.ExpireDate = Convert.ToDateTime(oDbDataReader["ExpireDate"]);

					if(oDbDataReader["AccountId"] != DBNull.Value)
						oBillDetail.AccountId = Convert.ToInt32(oDbDataReader["AccountId"]);

					if(oDbDataReader["Note"] != DBNull.Value)
						oBillDetail.Note = Convert.ToString(oDbDataReader["Note"]);
				}
				oDbDataReader.Close();
				return oBillDetail;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int AddBillDetail(string ID,DateTime?CreateDate,DateTime?ModifiedDate,DateTime?TimeStamp,string LineNo,string ProductCode,string ProductName,string Quantity,Double?Price,Double?Total,Double?OddQuantity,Double?Content,int?UnitType,DateTime?ExpireDate,int?AccountId,string Note)
		{
			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("INSERT INTO [BillDetail]([CreateDate],[ModifiedDate],[TimeStamp],[LineNo],[ProductCode],[ProductName],[Quantity],[Price],[Total],[OddQuantity],[Content],[UnitType],[ExpireDate],[AccountId],[Note])VALUES(@CreateDate,@ModifiedDate,@TimeStamp,@LineNo,@ProductCode,@ProductName,@Quantity,@Price,@Total,@OddQuantity,@Content,@UnitType,@ExpireDate,@AccountId,@Note)",CommandType.Text);
				if (CreateDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate",DbType.DateTime,CreateDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate",DbType.DateTime,DBNull.Value));
				if (ModifiedDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate",DbType.DateTime,ModifiedDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate",DbType.DateTime,DBNull.Value));
				if (TimeStamp.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp",DbType.DateTime,TimeStamp));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp",DbType.DateTime,DBNull.Value));
				if (LineNo!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@LineNo",DbType.String,LineNo));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@LineNo",DbType.String,DBNull.Value));
				if (ProductCode!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProductCode",DbType.String,ProductCode));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProductCode",DbType.String,DBNull.Value));
				if (ProductName!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProductName",DbType.String,ProductName));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProductName",DbType.String,DBNull.Value));
				if (Quantity!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Quantity",DbType.String,Quantity));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Quantity",DbType.String,DBNull.Value));
				if (Price.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Price",DbType.Double,Price));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Price",DbType.Double,DBNull.Value));
				if (Total.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Total",DbType.Double,Total));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Total",DbType.Double,DBNull.Value));
				if (OddQuantity.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@OddQuantity",DbType.Double,OddQuantity));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@OddQuantity",DbType.Double,DBNull.Value));
				if (Content.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Content",DbType.Double,Content));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Content",DbType.Double,DBNull.Value));
				if (UnitType.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@UnitType",DbType.Int32,UnitType));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@UnitType",DbType.Int32,DBNull.Value));
				if (ExpireDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ExpireDate",DbType.DateTime,ExpireDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ExpireDate",DbType.DateTime,DBNull.Value));
				if (AccountId.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId",DbType.Int32,AccountId));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId",DbType.Int32,DBNull.Value));
				if (Note!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Note",DbType.String,Note));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Note",DbType.String,DBNull.Value));

				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int AddBillDetail(BillDetail oBillDetail)
		{
			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("INSERT INTO [BillDetail]([CreateDate],[ModifiedDate],[TimeStamp],[LineNo],[ProductCode],[ProductName],[Quantity],[Price],[Total],[OddQuantity],[Content],[UnitType],[ExpireDate],[AccountId],[Note])VALUES(@CreateDate,@ModifiedDate,@TimeStamp,@LineNo,@ProductCode,@ProductName,@Quantity,@Price,@Total,@OddQuantity,@Content,@UnitType,@ExpireDate,@AccountId,@Note)",CommandType.Text);
				if (oBillDetail.CreateDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate",DbType.DateTime,oBillDetail.CreateDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate",DbType.DateTime,DBNull.Value));
				if (oBillDetail.ModifiedDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate",DbType.DateTime,oBillDetail.ModifiedDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate",DbType.DateTime,DBNull.Value));
				if (oBillDetail.TimeStamp.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp",DbType.DateTime,oBillDetail.TimeStamp));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp",DbType.DateTime,DBNull.Value));
				if (oBillDetail.LineNo!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@LineNo",DbType.String,oBillDetail.LineNo));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@LineNo",DbType.String,DBNull.Value));
				if (oBillDetail.ProductCode!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProductCode",DbType.String,oBillDetail.ProductCode));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProductCode",DbType.String,DBNull.Value));
				if (oBillDetail.ProductName!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProductName",DbType.String,oBillDetail.ProductName));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProductName",DbType.String,DBNull.Value));
				if (oBillDetail.Quantity!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Quantity",DbType.String,oBillDetail.Quantity));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Quantity",DbType.String,DBNull.Value));
				if (oBillDetail.Price.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Price",DbType.Double,oBillDetail.Price));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Price",DbType.Double,DBNull.Value));
				if (oBillDetail.Total.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Total",DbType.Double,oBillDetail.Total));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Total",DbType.Double,DBNull.Value));
				if (oBillDetail.OddQuantity.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@OddQuantity",DbType.Double,oBillDetail.OddQuantity));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@OddQuantity",DbType.Double,DBNull.Value));
				if (oBillDetail.Content.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Content",DbType.Double,oBillDetail.Content));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Content",DbType.Double,DBNull.Value));
				if (oBillDetail.UnitType.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@UnitType",DbType.Int32,oBillDetail.UnitType));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@UnitType",DbType.Int32,DBNull.Value));
				if (oBillDetail.ExpireDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ExpireDate",DbType.DateTime,oBillDetail.ExpireDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ExpireDate",DbType.DateTime,DBNull.Value));
				if (oBillDetail.AccountId.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId",DbType.Int32,oBillDetail.AccountId));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId",DbType.Int32,DBNull.Value));
				if (oBillDetail.Note!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Note",DbType.String,oBillDetail.Note));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Note",DbType.String,DBNull.Value));

				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int UpdateBillDetail(string ID,DateTime?CreateDate,DateTime?ModifiedDate,DateTime?TimeStamp,string LineNo,string ProductCode,string ProductName,string Quantity,Double?Price,Double?Total,Double?OddQuantity,Double?Content,int?UnitType,DateTime?ExpireDate,int?AccountId,string Note)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("UPDATE [BillDetail] SET [CreateDate]=@CreateDate,[ModifiedDate]=@ModifiedDate,[TimeStamp]=@TimeStamp,[LineNo]=@LineNo,[ProductCode]=@ProductCode,[ProductName]=@ProductName,[Quantity]=@Quantity,[Price]=@Price,[Total]=@Total,[OddQuantity]=@OddQuantity,[Content]=@Content,[UnitType]=@UnitType,[ExpireDate]=@ExpireDate,[AccountId]=@AccountId,[Note]=@Note WHERE [ID]=@ID",CommandType.Text);
				if (CreateDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate",DbType.DateTime,CreateDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate",DbType.DateTime,DBNull.Value));
				if (ModifiedDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate",DbType.DateTime,ModifiedDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate",DbType.DateTime,DBNull.Value));
				if (TimeStamp.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp",DbType.DateTime,TimeStamp));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp",DbType.DateTime,DBNull.Value));
				if (LineNo!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@LineNo",DbType.String,LineNo));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@LineNo",DbType.String,DBNull.Value));
				if (ProductCode!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProductCode",DbType.String,ProductCode));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProductCode",DbType.String,DBNull.Value));
				if (ProductName!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProductName",DbType.String,ProductName));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProductName",DbType.String,DBNull.Value));
				if (Quantity!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Quantity",DbType.String,Quantity));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Quantity",DbType.String,DBNull.Value));
				if (Price.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Price",DbType.Double,Price));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Price",DbType.Double,DBNull.Value));
				if (Total.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Total",DbType.Double,Total));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Total",DbType.Double,DBNull.Value));
				if (OddQuantity.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@OddQuantity",DbType.Double,OddQuantity));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@OddQuantity",DbType.Double,DBNull.Value));
				if (Content.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Content",DbType.Double,Content));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Content",DbType.Double,DBNull.Value));
				if (UnitType.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@UnitType",DbType.Int32,UnitType));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@UnitType",DbType.Int32,DBNull.Value));
				if (ExpireDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ExpireDate",DbType.DateTime,ExpireDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ExpireDate",DbType.DateTime,DBNull.Value));
				if (AccountId.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId",DbType.Int32,AccountId));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId",DbType.Int32,DBNull.Value));
				if (Note!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Note",DbType.String,Note));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Note",DbType.String,DBNull.Value));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID",DbType.String,ID));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int UpdateBillDetail(BillDetail oBillDetail)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("UPDATE [BillDetail] SET [CreateDate]=@CreateDate,[ModifiedDate]=@ModifiedDate,[TimeStamp]=@TimeStamp,[LineNo]=@LineNo,[ProductCode]=@ProductCode,[ProductName]=@ProductName,[Quantity]=@Quantity,[Price]=@Price,[Total]=@Total,[OddQuantity]=@OddQuantity,[Content]=@Content,[UnitType]=@UnitType,[ExpireDate]=@ExpireDate,[AccountId]=@AccountId,[Note]=@Note WHERE [ID]=@ID",CommandType.Text);
				if (oBillDetail.CreateDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate",DbType.DateTime,oBillDetail.CreateDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate",DbType.DateTime,DBNull.Value));
				if (oBillDetail.ModifiedDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate",DbType.DateTime,oBillDetail.ModifiedDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate",DbType.DateTime,DBNull.Value));
				if (oBillDetail.TimeStamp.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp",DbType.DateTime,oBillDetail.TimeStamp));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp",DbType.DateTime,DBNull.Value));
				if (oBillDetail.LineNo!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@LineNo",DbType.String,oBillDetail.LineNo));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@LineNo",DbType.String,DBNull.Value));
				if (oBillDetail.ProductCode!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProductCode",DbType.String,oBillDetail.ProductCode));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProductCode",DbType.String,DBNull.Value));
				if (oBillDetail.ProductName!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProductName",DbType.String,oBillDetail.ProductName));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProductName",DbType.String,DBNull.Value));
				if (oBillDetail.Quantity!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Quantity",DbType.String,oBillDetail.Quantity));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Quantity",DbType.String,DBNull.Value));
				if (oBillDetail.Price.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Price",DbType.Double,oBillDetail.Price));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Price",DbType.Double,DBNull.Value));
				if (oBillDetail.Total.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Total",DbType.Double,oBillDetail.Total));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Total",DbType.Double,DBNull.Value));
				if (oBillDetail.OddQuantity.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@OddQuantity",DbType.Double,oBillDetail.OddQuantity));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@OddQuantity",DbType.Double,DBNull.Value));
				if (oBillDetail.Content.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Content",DbType.Double,oBillDetail.Content));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Content",DbType.Double,DBNull.Value));
				if (oBillDetail.UnitType.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@UnitType",DbType.Int32,oBillDetail.UnitType));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@UnitType",DbType.Int32,DBNull.Value));
				if (oBillDetail.ExpireDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ExpireDate",DbType.DateTime,oBillDetail.ExpireDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ExpireDate",DbType.DateTime,DBNull.Value));
				if (oBillDetail.AccountId.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId",DbType.Int32,oBillDetail.AccountId));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId",DbType.Int32,DBNull.Value));
				if (oBillDetail.Note!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Note",DbType.String,oBillDetail.Note));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Note",DbType.String,DBNull.Value));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID",DbType.String,oBillDetail.ID));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int RemoveBillDetail(BillDetail oBillDetail)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("DELETE FROM [BillDetail] WHERE [ID]=@ID",CommandType.Text);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID",DbType.String,oBillDetail.ID));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int RemoveBillDetail(string ID)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("DELETE FROM [BillDetail] WHERE [ID]=@ID",CommandType.Text);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID",DbType.String,ID));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
	}
}
